#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
void solve()
{
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n),b(q);
    deque<ll> pq;
    for(ll i=0;i<n;i++)
    {
        cin >> a[i];
        pq.push_back(a[i]);
    }
    for(ll j=0;j<q;j++)
    {
        cin >> b[j];
        if(b[j]==1)
        {
            ll t = pq.front();
            pq.pop_front();
            pq.push_back(t);

        }
        else 
        {
            ll t=pq.back();
            pq.pop_back();
            pq.push_front(t);
        }
    }
    for(auto &i:pq)
    {
        cout << i << " ";
    }
    return;
}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
